# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.
#
# AUR Maintainer: Morgan <morganamilo@archlinux.org>

pkgname=paru
pkgver=2.0.4
pkgrel=1
pkgdesc='Feature packed AUR helper.'
url='https://github.com/morganamilo/paru'
arch=('x86_64' 'aarch64')
license=('GPL3')
depends=('git' 'pacman')
makedepends=('rust' 'cargo')
optdepends=('asp: downloading repo pkgbuilds' 'bat: colored pkgbuild printing'
            'devtools: build in chroot')
backup=("etc/$pkgname.conf")
source=("https://github.com/Morganamilo/$pkgname/archive/v$pkgver.tar.gz")
sha512sums=('bb2e85d74cae57a7fa48a857676c0bb536faa6e8e3c30a868ccf74689b1577523a07db95e4b336b71632a615ddf15a23d429129eebb218b4de0149c9ef9ded3b')

build () {
  cd "$pkgname-$pkgver"

  if pacman -T pacman-git > /dev/null; then
    _features+="git,"
  fi

  if [[ $(rustc -V) == *"nightly"* ]]; then
    _features+="backtrace,"
  fi

  if [[ $CARCH != x86_64 ]]; then
    export CARGO_PROFILE_RELEASE_LTO=off
  fi

  cargo build --locked --features "${_features:-}" --release --target-dir target
}

package() {
  cd "$pkgname-$pkgver"

  install -Dm 755 "target/release/$pkgname" "$pkgdir/usr/bin/$pkgname"
  install -Dm 644 "$pkgname.conf" "$pkgdir/etc/$pkgname.conf"

  install -Dm 644 "man/$pkgname.8" "$pkgdir/usr/share/man/man8/$pkgname.8"
  install -Dm 644 "man/$pkgname.conf.5" \
    "$pkgdir/usr/share/man/man5/$pkgname.conf.5"

  install -Dm 644 completions/bash \
    "$pkgdir/usr/share/bash-completion/completions/$pkgname.bash"
  install -Dm 644 completions/fish \
  "$pkgdir/usr/share/fish/vendor_completions.d/$pkgname.fish"
  install -Dm 644 completions/zsh \
    "$pkgdir/usr/share/zsh/site-functions/_${pkgname}"
}

